package cn.aws360.boot.wechat.biz.mp.handler;

import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author junnan
 */
@Slf4j
@Component
public class WxMpEvent4LocationHandler implements WxMpMessageHandler {

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage mpXmlMessage, Map<String, Object> context,
                                    WxMpService wxMpService, WxSessionManager wxSessionManager) {
        String openId = mpXmlMessage.getFromUser();
        String location = mpXmlMessage.getLocationY() + "，" + mpXmlMessage.getLocationX();

        if (mpXmlMessage.getMsgType().equals(WxConsts.XmlMsgType.LOCATION)) {
            log.info("[接收地理位置消息] openId: {}, location: {}", openId, location);
            return null;
        }

        log.info("[上报地理位置事件] openId: {}, location: {}", openId, location);
        return null;
    }

}
